package magicbattle.game.character.effect;

import magicbattle.game.Player;
import magicbattle.game.character.DamageType;
import magicbattle.game.character.Target;
import magicbattle.game.character.TargetType;

public class InstantEffect extends Effect {
	public enum DamagePercentType {
		NONE, BASICDAMAGE, OWNMAXHEALTH, TARGETMAXHEALTH;
	}

	private DamageType damageType;

	private int damageFix;

	private DamagePercentType damagePercentKind;
	private float damagePercentage;

	public InstantEffect(EffectType effectType, TargetType targetType,
			DamageType damageType, int damageFix,
			DamagePercentType damagePercentKind, float damagePercentage) {
		super();
		this.effectType = effectType;
		this.targetType = targetType;
		this.damageType = damageType;
		this.damageFix = damageFix;
		this.damagePercentKind = damagePercentKind;
		this.damagePercentage = damagePercentage;

		checkValues();
	}

	public InstantEffect(EffectType effectType, TargetType targetType,
			DamageType damageType, int damageFix) {
		super();
		this.effectType = effectType;
		this.targetType = targetType;
		this.damageType = damageType;
		this.damageFix = damageFix;
		this.damagePercentKind = DamagePercentType.NONE;
		this.damagePercentage = 0;

		checkValues();
	}

	public InstantEffect(EffectType effectType, DamageType damageType,
			DamagePercentType damagePercentKind, float damagePercentage) {
		super();
		this.effectType = effectType;
		this.damageType = damageType;
		this.damageFix = 0;
		this.damagePercentKind = damagePercentKind;
		this.damagePercentage = damagePercentage;

		checkValues();
	}

	private void checkValues() {
		// check types for heal
		if ((this.effectType == EffectType.INSTANTHEAL)
				&& (this.damageType == DamageType.MAGICAL)) {
			return;
		}

		if ((this.effectType == EffectType.INSTANTDAMAGE)
				&& !(this.damageType == DamageType.DOT)) {
			return;
		}

		System.out
				.println("invalid combination of parameters for class: InstantEffect - "
						+ this.effectType + " - " + this.damageType);
	}

	@Override
	public void action(Player currentPlayer, Player targetPlayer) {
		int damage = this.damageFix;

		// calcuate damage/heal
		switch (this.damagePercentKind) {
		case NONE:
			break;
		case BASICDAMAGE:
			damage += (int) (currentPlayer.getCurrentAttribute()
					.randomOfAttack() * (this.damagePercentage / 100));
			break;
		case OWNMAXHEALTH:
			damage += (int) (currentPlayer.getNormalAttribute().getHealth() * (this.damagePercentage / 100));
			break;
		case TARGETMAXHEALTH:
			damage += (int) (targetPlayer.getCurrentAttribute().getHealth() * (this.damagePercentage / 100));
			break;
		}

		// process damage
		if (this.effectType == EffectType.INSTANTDAMAGE) {
			targetPlayer.processDamage(damage, this.damageType);
		} else {
			targetPlayer.processHeal(damage);
		}
	}
}
